/* 
 * @author wxj
 * @version 1.4
 * ���ܣ���֯����
 * 2006-12-27
 */

package com.zjht.gmcc.servlet.sys;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;


public class PopedomAdd extends BaseServlet {

	private static final long serialVersionUID = 1L;


	public boolean process(HttpServletRequest request, HttpServletResponse response,HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)throws Exception {
		int i_flag = 0;

		String s_zzlxid = request.getParameter("zzlxid").toString();
		String s_bmzwid = request.getParameter("bmzwid").toString();
		String url = "/sys/popedom.jsp?zzlx=" + s_zzlxid + "&bmzw=" + s_bmzwid;

		String s_sql = null;
		PreparedStatement ps = null;

		s_sql = "delete from dutypopedom where dutyid = ?";
		ps = myJDBC.prepareStatement(s_sql);
		ps.setString(1, s_bmzwid);
		ps.executeUpdate();
		s_sql = null;
		ps.close();
		ps = null;
		int Iicount = Integer.parseInt(request.getParameter("Icount").toString());

		String s_tjcheck = null;
		String s_gnid = null;

		s_sql = "INSERT INTO dutypopedom(dutyid,menuid) VALUES(?,?)";
		ps = myJDBC.prepareStatement(s_sql);

		for (int i = 1; i <= Iicount; i++) {
			s_tjcheck = request.getParameter("tjcheck" + Integer.toString(i)).toString();
			if (!s_tjcheck.equals("0")) {
				s_gnid = request.getParameter("gnid" + Integer.toString(i)).toString();

				ps.setString(1, s_bmzwid);
				ps.setString(2, s_gnid);
				i_flag = ps.executeUpdate();

				if (i_flag == 0) {
					break;
				}
			}
		}

		s_sql = null;
		ps.close();
		ps = null;

		String act = "授权";
		if (i_flag > 0) {
			alert(out, act + "成功",url);
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return i_flag > 0;
	}
}
